<?php
class IncomsController extends AppController {

    public $helpers = array('Html', 'Form');
    public $components = array('Session');

    public function index() {
        $pageTitle ="Worldwide Seventhday-Adventisth Church - Kwabrafoso: Income";
        $in_record_data = $this->Incom->find('all');
        $this->set(compact('in_record_data','pageTitle'));
    }

    
    public function add(){
    $pageTitle ="SDA Church - Kwabrafoso: Enter Income";
     if($_POST){
       // pr($_POST);
        $data['Incom'] = array(
            'dondate' => $_POST['dondate'],
            'recno' => $_POST['recno'],
            'mshipno' => $_POST['mshipno'],
            'donname' => $_POST['donname'],
            'description' => $_POST['description'],
            'total' => $_POST['total'],
            'contotal' => $_POST['contotal'],
            'contithe' => $_POST['contithe'],
            'conplangive' => $_POST['conplangive'],
            'conthanks' => $_POST['conthanks'],
            'conloose' => $_POST['conloose'],
            'conmission' => $_POST['conmission'],
            'conothers' => $_POST['conothers'],
            'disttotal' => $_POST['disttotal'],
            'distplangive' => $_POST['distplangive'],
            'distothers' => $_POST['distothers'],
            'loctotal' => $_POST['loctotal'],
            'locpoorandneedy' => $_POST['locpoorandneedy'],
            'locplangive' => $_POST['locplangive'],
            'locthanks' => $_POST['locthanks'],
            'locloose' => $_POST['locloose'],
            'locsabsch' => $_POST['locsabsch'],
            'locsabschbooks' => $_POST['locsabschbooks'],
            'locchnsab' => $_POST['locchnsab'],
            'locwelfare' => $_POST['locwelfare'],
            'locfuneral' => $_POST['locfuneral'],
            'locproject' => $_POST['locproject'],
            'locothers' => $_POST['locothers']
        );

        if(!$this->Incom->save($data)){
            $this->Session->setFlash('Error Saving Income');
        }else{
             $this->Session->setFlash('Income Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','errorMsg'));
}
    
    // A functin to delete Incomes
    public function delete($id = null)
    {
       if (!$id) 
       {
        $this->Session->setFlash('Invalid id for Income');
        $this->redirect(array('action' => 'index'));
    }
    if ($this->Incom->delete($id)) 
    {
        $this->Session->setFlash('Income Deleted Please');
    } else 
    {
        $this->Session->setFlash(__('Income Not Deleted', true));
    }
    $this->redirect(array('action' => 'index'));
}

    // A functin to edit Incomes
    function edit($id = null){
    $record_id = $id;
    $conditions = array('Incom.id' => $record_id);
    $record = $this->Incom->find('first', array('conditions' => $conditions, 'recursive' => 1));
   // pr($record);
            
     $pageTitle ="SDA Church - Kwabrafoso: Edit Income";
     if($_POST){
        //pr($_POST);
        $data['Incom'] = array(
            'dondate' => $_POST['dondate'],
            'recno' => $_POST['recno'],
            'mshipno' => $_POST['mshipno'],
            'donname' => $_POST['donname'],
            'description' => $_POST['description'],
            'total' => $_POST['total'],
            'contotal' => $_POST['contotal'],
            'contithe' => $_POST['contithe'],
            'conplangive' => $_POST['conplangive'],
            'conthanks' => $_POST['conthanks'],
            'conloose' => $_POST['conloose'],
            'conmission' => $_POST['conmission'],
            'conothers' => $_POST['conothers'],
            'disttotal' => $_POST['disttotal'],
            'distplangive' => $_POST['distplangive'],
            'distothers' => $_POST['distothers'],
            'loctotal' => $_POST['loctotal'],
            'locpoorandneedy' => $_POST['locpoorandneedy'],
            'locplangive' => $_POST['locplangive'],
            'locthanks' => $_POST['locthanks'],
            'locloose' => $_POST['locloose'],
            'locsabsch' => $_POST['locsabsch'],
            'locsabschbooks' => $_POST['locsabschbooks'],
            'locchnsab' => $_POST['locchnsab'],
            'locwelfare' => $_POST['locwelfare'],
            'locfuneral' => $_POST['locfuneral'],
            'locproject' => $_POST['locproject'],
            'locothers' => $_POST['locothers']
        );

        if(!$this->Incom->save($data)){
            $this->Session->setFlash('Error Saving Data');
        }else{
             $this->Session->setFlash('Data Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','record'));
}

     // A functin to view Records
    public function view($id) {
    if (!$id) {
        throw new NotFoundException(__('Invalid Record'));
    }

    $incom = $this->Incom->findById($id);
    if (!$incom) {
        throw new NotFoundException(__('Invalid Record'));
    }
    $this->set('incom', $incom);
}

function report($id = null){
    $record_id = $id;
    $conditions = array('Incom.id' => $record_id);
    $record = $this->Incom->find('first', array('conditions' => $conditions, 'recursive' => 1));
//    pr($record);

}

}
?>
